package com.mark.spring.annotation.life.cycle.init.disp;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @Description: city POJO
 * @Author: Mark
 * @CreateDate: 2019/9/21 18:27
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 */
public class City implements InitializingBean, DisposableBean,BeanPostProcessor {

    public City(){
        System.out.println("City....Construct");
    }
    
    public void  initMethod(){
        System.out.println("City....initMethod");
    }

    private void destroyMethod() {
        System.out.println("City....destroyMethod");
    }

    @PostConstruct
    public void postConstruct(){
        System.out.println("City..@PostConstruct");
    }

    @PreDestroy
    public void preDestroy(){
        System.out.println("City..@PreDestroy");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("City..DisposableBean..destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("City..InitializingBean..afterPropertiesSet");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("city")){
            System.out.println(beanName+"city...BeanPostProcessor...postProcessBeforeInitialization");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.equals("city")){
            System.out.println("city...BeanPostProcessor...postProcessAfterInitialization");
        }
        return bean;
    }
}
